package com.zhou.project.modules.circle.circlePostsComment.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.project.components.base.service.BaseService;
import com.zhou.project.modules.circle.circlePostsComment.dao.CircleCommentDao;
import com.zhou.project.modules.circle.circlePostsComment.entity.CirclePostsComment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.constraints.NotNull;
import java.sql.Wrapper;

@Service
public class CircleCommentService extends BaseService<CircleCommentDao, CirclePostsComment> {

    public Page<CirclePostsComment> page(CirclePostsComment entity) {

        //分页查询对象
        Page<CirclePostsComment> page = Page.of(entity.getCurrent(), entity.getSize());

        QueryWrapper<CirclePostsComment> wrapper = new QueryWrapper<>();
        if (entity.getUserId() != null)
            wrapper.eq("user_id", entity.getUserId());
        if (entity.getPostsId() != null)
            wrapper.eq("posts_id", entity.getPostsId());
        if (entity.getPid()!=null)
            wrapper.eq("id",entity.getPid());

        return baseMapper.selectPage(page, wrapper);
    }

    //物理删除(当话题被删除时调用)
    @Transactional
    public void deleteAll(int postsId){
        baseMapper.deleteAll(postsId);
    }
}
